/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "../include/fsd.h"

/**
 * @brief Extracts the directory name from a path.
 *
 * This function duplicates the path, finds the last slash, and null-terminates the string at that point.
 *
 * @param path The path from which to extract the directory name.
 * @return char* The directory name, or NULL if no slash is found.
 */
char* Sdirname(const char* path) {
	char *dir = strdup(path);
	char *base = Sstrchr(dir, '/');

	if (base) {
		*base = '\0';
	} else {
		Sfree(dir);
		return NULL;
	}
	return dir;
}
